/**
 * 角色详情tab
 */
seajs.use(['mmj-jquery', "tabs", "overlay", "modules/common/my-style", "handlebars"], function($, Tab, Overlay, Style, Handlebars) {
    var goodShow = $("#goods-show");
    var goodDetail = $("#goods-detail");
    /*装备道具模板*/
    var tlEquipTpl = $("#tlEquipTpl").html();
    tlEquipTpl = Handlebars.compile(tlEquipTpl);
    /*真元模板*/
    var tlZhenyuanTpl = $("#tlZhenyuanTpl").html();
    tlZhenyuanTpl = Handlebars.compile(tlZhenyuanTpl);
    /*宝石模板*/
    var tlGemTpl = $("#tlGemTpl").html();
    tlGemTpl = Handlebars.compile(tlGemTpl);
    /*子女tip模板*/
    var tlChildrenTpl = $("#tlChildrenTpl").html();
    tlChildrenTpl = Handlebars.compile(tlChildrenTpl);
    /*套装属性模板*/
    var tlTRLevelTpl = $("#tlTRLevelTpl").html();
    tlTRLevelTpl = Handlebars.compile(tlTRLevelTpl);

    var singleConfig = {
        practiceTab: false,
        animalTab: false
    };

    /* 卡牌是否已绑定 */
    Handlebars.registerHelper('fn_isBind', function(bindType, option) {
        return bindType == 1 ? "已绑定" : "未绑定";
    });

    /* 卡牌是否贵重 */
    Handlebars.registerHelper('fn_isguizhong', function(guiZhong, option) {
        return guiZhong == 1 ? "贵重" : "";
    });

    /* 子女装备icon */
    Handlebars.registerHelper('fn_childCardEquip', function(icon, option) {
        var index = icon.lastIndexOf('_');
        var name = icon.substr(0, index);
        var count = icon.substr(index + 1);
        return '<div class="card-icon c-count' + count + ' fn-pngfix" style="background-image: url(\'' + IMAGE_PATH + '/card/' + name + '.png\');"></div>';
    });
    /* 子女使用心得变色 */
    Handlebars.registerHelper('fn_childCardXinDe', function(desc, option) {
        return ('<span>' + desc + '</span>').replace('#c777777', '</span><span style="color: #777;">');
    });
    /* 子女研读加成 */
    Handlebars.registerHelper('fn_childExtraVal', function(val, option) {
        return val > 0 ? '<span style="color: #840000; padding-left: 10px;">+' + val + '</span>' : "";
    });
    /* 令牌宝石 */
    Handlebars.registerHelper('fn_LPGemsList', function(obj, option) {
        var stones = obj.runeStone;
        var html = "";

        for (var i = 0, len = stones.length; i < len; i++) {
            var color = stones[i].stoneColor; // 宝珠的颜色 0.未开启 1.红 2.绿 3.蓝 4.黄 5.未镶嵌
            var desc = stones[i].stoneDesc;

            switch (color) {
                case 0:
                    html += '<p class="lp-gem0" style="color: #605C4F;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
                case 1:
                    html += '<p class="lp-gem1" style="color: #DA161A;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
                case 2:
                    html += '<p class="lp-gem2" style="color: #00FF00;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
                case 3:
                    html += '<p class="lp-gem3" style="color: #00B4FF;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
                case 4:
                    html += '<p class="lp-gem4" style="color: #FFFF00;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
                case 5:
                    html += '<p class="lp-gem5" style="color: #009933;"><span class="lp-gem"></span>' + desc + '</p>';
                    break;
            }
        }
        return html;
    });
    /* 令牌扩展属性 */
    Handlebars.registerHelper('fn_LPOtherInfoList', function(obj, option) {
        var attrs = obj.attrDesc;
        var html = "";

        for (var i = 0, len = attrs.length; i < len; i++) {
            var color = attrs[i].attrDescColor; // 被动技能的颜色 0.未开启 1.未激活 2.已激活
            var desc = attrs[i].attrDesc;

            switch (color) {
                case 0:
                    html += '<p class="c-g-d" style="color: #605C4F">' + desc + '</p>';
                    break;
                case 1:
                    html += '<p class="c-n-g" style="color: #009933">' + desc + '</p>';
                    break;
                case 2:
                    html += '<p class="c-n-g" style="color: #009933">' + desc + '</p>';
                    break;
            }
        }
        return html;
    });
    /* 令牌被动技能 */
    Handlebars.registerHelper('fn_LPbuffSkill', function(obj, option) {
        var color = obj.buffDescColor;
        var desc = obj.buffDesc;
        var html = "";

        switch (color) {
            case 0:
                html += '<p class="c-g-d" style="color: #605C4F">' + desc + '</p>';
                break;
            case 1:
                html += '<p class="c-n-g" style="color: #605C4F">' + desc + '</p>';
                break;
            case 2:
                html += '<p class="c-n-g" style="color: #009933">' + desc + '</p>';
                break;
        }

        return html;
    });
    /* 豪侠印扩展属性 */
    Handlebars.registerHelper('fn_HXYOtherInfoList', function(obj, option) {
        var hxyExtraEffectList = obj.hxyExtraEffectList;
        var HXYOtherInfoList= ["血上限","血上限","血回复速度","气上限","气上限","气回复速度","冰攻击","冰抗性","降低目标冰抗下限","火攻击","火抗性","降低目标火抗下限","玄攻击","玄抗性","降低目标玄抗下限","毒攻击","毒抗性","降低目标毒抗下限","所有抗性","外功攻击","基础外功攻击","武器基础外功攻击","外功防御","基础外功防御","防具基础外功防御","抵消外功伤害","内功攻击","基础内功攻击","武器基础内功攻击","内功防御","基础内功防御","防具基础内功防御","抵消内功伤害","攻击速度","冷却时间","命中","闪避","会心","几率无视对方防御","移动速度","反射伤害","气抵消伤害","力量","灵气","体力","定力","身法","会心防御","所有属性","血偷取","气偷取","会心防御","会心防御","会心防御","忽略目标冰抗","忽略目标火抗","忽略目标玄抗","忽略目标毒抗","基础外功攻击","基础内功攻击","基础外功防御","基础内功防御","基础命中","基础闪避"];
        var skillEffectList = ["散功", "封印", "围困", "失明", "麻痹", "封穴", "昏睡"] ;
        var html = '<p class="c-y-d">绶印属性</p>';
        for(var i=0;i<7;i++){
            html +='<p class="c-y-d">'+HXYOtherInfoList[obj.hxyExtraAttrList[i].type]+'+'+obj.hxyExtraAttrList[i].value+'</p>';
        }
        var effectNumber=0;
        var effectStr='';

        for (var i = 0, len = hxyExtraEffectList.length; i < len; i++) {
            if(hxyExtraEffectList[i].effectLevel!=0){
                effectStr+='<p class="c-g-d">所受'+skillEffectList[i]+'减少'+(hxyExtraEffectList[i].effectLevel/10)+'秒</p>';
                effectNumber++;
            }
        }
        var effectNumberAdd=0;
        for (var i = 0, len = hxyExtraEffectList.length; i < len; i++) {
            if(hxyExtraEffectList[i].effectLevel==0){
                effectStr+='<p class="c-n-g">(未激活)豪侠印达'+((effectNumber+effectNumberAdd)*15+10)+'级后可激活</p>';
                effectNumberAdd++;
            }
        }
        html +='<p class="c-p-d">豪侠绶印效果（'+effectNumber+'/7）</p>';
        html +=effectStr;
        return html;
    });
    /* 天道王权升灵属性 */
    Handlebars.registerHelper('fn_tiandaowangquanAttr', function(obj, option) {
        var handMakeStatus=obj.handMakeStatus;
        var handMakeType=obj.handMakeType;
        var handMakeLevel=obj.handMakeLevel;
        var handMakeRate=obj.handMakeRate;
        var html = '';
        if(handMakeStatus==1){
            if(handMakeType==0){
                if(handMakeLevel==0){
                    html='<span class="c-b-d">&nbsp;尚未升灵</span>';
                }else{
                    html='<p class="c-b-d">&nbsp;升灵度：<span class="c-y-d">'+handMakeLevel+'/9</span>(+'+handMakeRate+'%)</p>';
                }
            }else if(handMakeType==1){
                html='<p class="c-b-d">&nbsp;升灵度：<span class="c-y-d">'+handMakeLevel+'/9</span>(+'+handMakeRate+'%)</p>';
            }else if(handMakeType==2){
                html='<p class="c-b-d">天道：(+'+handMakeRate+'%)</p>';
            }
        }
        return html;
    });
    /* 扩展属性   包涵【天道王权追加属性】 */
    Handlebars.registerHelper('fn_tiandaowangquanAddAttr', function(obj, option) {
        var handMakeStatus=obj.handMakeStatus;
        var handMakeType=obj.handMakeType;
        var handMakeLevel=obj.handMakeLevel;
        var handMakeRate=obj.handMakeRate;
        var html = '';
        var isAddAttr=0;
        if(handMakeStatus==1){
            if(handMakeType==0){
                if(handMakeLevel==0){

                }else{
                    isAddAttr=1;
                }
            }else if(handMakeType==1){
                isAddAttr=1;
            }else if(handMakeType==2){
                isAddAttr=1;
            }
        }
        if(isAddAttr>0){
            for(var i=0;i<obj.extAttr.length;i++){
                html+='<p class="c-y-d">'+obj.extAttr[i].value+'&nbsp;<span class="c-b-d">+'+obj.extAttrTianDao[i].value+'</span>'+'</p>';
            }
        }else{
            if(typeof(obj.extAttr)!="undefined")
            {
                for(var i=0;i<obj.extAttr.length;i++){
                    html+='<p class="c-y-d">'+obj.extAttr[i].value+'</p>';
                }
            }
        }
        return html;
    });
    /* 【天道王权样式处理1】 */
    Handlebars.registerHelper('fn_tiandaowangquanIco1', function(obj, option) {
        var handMakeStatus=obj.handMakeStatus;
        var handMakeType=obj.handMakeType;
        var handMakeLevel=obj.handMakeLevel;
        var handMakeRate=obj.handMakeRate;
        var html='<div class="model">';
        var isAddAttr=0;
        if(handMakeStatus==1){
            if(handMakeType==1){
                html='<div class="model wq-title">';
            }else if(handMakeType==2){
                html='<div class="model td-title">';
            }
        }
        return html;
    });
    /* 【天道王权样式处理2】 */
    Handlebars.registerHelper('fn_tiandaowangquanIco2', function(obj, option) {
        var handMakeStatus=obj.handMakeStatus;
        var handMakeType=obj.handMakeType;
        var handMakeLevel=obj.handMakeLevel;
        var handMakeRate=obj.handMakeRate;
        var html='<div class="img-cont-box"></div>';
        var isAddAttr=0;
        if(handMakeStatus==1){
            if(handMakeType==1){
                html='<div class="img-cont-box img-cont-wq"></div>';
            }else if(handMakeType==2){
                html='<div class="img-cont-box img-cont-td"></div>';
            }
        }
        return html;
    });
    /**
     * 宝鉴
     */
    goodShow.delegate('.bj-show-wrap .has-tip', 'mouseover', function(e) {
        $(this).siblings('.bj-tips').show();
    });
    goodShow.delegate('.bj-show-wrap .has-tip', 'mouseout', function(e) {
        $(this).siblings('.bj-tips').hide();
    });

    /* 暗器扩展属性 */
    Handlebars.registerHelper('fn_AQOtherInfoList', function(obj, option) {
        var stBHaveNewInfo = obj.stBHaveNewInfo;
        var html = '';
        if(stBHaveNewInfo==1){
            var attrList=obj.attrList;
            for(var i=0;i<attrList.length;i++){
                if(attrList[i].desc=='尚未淬毒'){
                    html +='<p class="c-n-g">'+attrList[i].desc+'</p>';
                }else{
                    var attr=attrList[i].desc.split("+");
                    html +='<p class="c-g-d">'+attr[0]+' +'+attr[1]+'<span class="c-b-d">+'+attr[2]+'</span>'+'</p>';
                }
            }
        }
        return html;
    });
    /* 暗器扩展属性 */
    Handlebars.registerHelper('fn_AQOtherSkillList', function(obj, option) {
        var stBHaveNewInfo = obj.stBHaveNewInfo;
        var html = '';
        if(stBHaveNewInfo==1){
            html = '<p class="c-p-d">暗器连击技能</p>';
            var attrList=obj.darkSkillDescLists;
            for(var i=0;i<attrList.length;i++){
                var attr=attrList[i].desc.split("%");
                html +='<p class="c-g-d">'+attr[0]+'%<span class="c-b-d">'+attr[1]+'%）</span>'+'<span class="c-g-d">'+attr[2].replace('）','')+'</span></p>';
            }
        }
        return html;
    });
    /*
     * 优化后tab
     * @author maple
     * @date 2013.08.13
     */
    goodShow.delegate('span.tab-item', 'click', function(e) {
        var elem = $(e.target);
        /*tab样式*/
        elem.parent().addClass('tab-active').siblings('.li').removeClass('tab-active');
        /*切换内容*/
        var cont = elem.data('cont');
        goodDetail.html($('#' + cont).html());

        if (cont == 'tab_3') {
            new Tab({
                element: '.animal',
                triggers: '.tab_title a',
                panels: '.tab_box',
                activeTriggerClass: 'curr',
                triggerType: 'click'
            });
            /*珍兽切换（珍兽）*/
            new Tab({
                element: '.animal',
                triggers: '.animal-item',
                panels: '.animal-info',
                activeTriggerClass: 'active',
                triggerType: 'click'
            });




        } else if (cont == 'tab_6') {
            /*修炼交互（修炼|经脉）*/
            new Tab({
                element: '.practice',
                triggers: '.practice-item',
                panels: '.role-good-cont',
                activeTriggerClass: 'active',
                triggerType: 'click'
            });
        } else if (cont == 'tab_7') {
            /*角色真元渲染*/
            (function() {
                var repStr = {
                    '#R': '</span><span style="color:red;">',
                    '#G': '</span><span style="color:green;">',
                    '#B': '</span><span style="color:blue;">',
                    '#K': '</span><span style="color:black;">',
                    '#P': '</span><span style="color:#f9c;">',
                    '#H': '</span><span style="color:#00FFFF;">',
                    '#I': '</span><span style="color:#ffc;">',
                    '#Y': '</span><span style="color:yellow;">',
                    '#W': '</span><span style="color:white;">',
                    '#b': '</span><span style="color:#fdeb78;">'
                };
                var describe = $(".zhenyuan-tip").find(".zhenyuan-describe");
                var html = "";
                describe.length && $.each(describe, function() {
                    var flag = false;
                    html = this.innerHTML;
                    html = html.replace(/##/g, "#").replace(/#R|#r|\\n/g, '<br>').replace(/(#[A-Z|a-z])/g, function(args0) {
                        return repStr[args0] || args0;
                    }).replace(/#[c|C]([0-9|A-F|a-f]{6})/g, function(args0, args1) {
                        return '</span><span style="color:#' + args1 + ';">';
                    }).replace(/#[g|e][0-9|A-F|a-f]{6}/g, '')
                        .replace(/#[b|u]/g, '')
                        .replace(/#([^0-9|A-F|a-f])/g, function(args0, args1) {
                            return args1;
                        });
                    this.innerHTML = html;
                });
                var zyQt = [];
                var zyKd = [];
                var zyPosition = ['.qiantian1', '.qiantian2', '.qiantian3', '.qiantian4', '.qiantian5', '.qiantian6', '.kundi1', '.kundi2', '.kundi3', '.kundi4', '.kundi5', '.kundi6'];
                var zyGrade = ['', 'white', 'white', 'blue', 'purple', 'orange','yellow'];
                var zyGradeDes = ['', '', '', '已放入6枚真元且最低品质为蓝色', '已放入6枚真元且最低品质为紫色', '已放入6枚真元且最低品质为橙色'];
                var getGrade = function(n, g) {
                    g = Number(g) || 0;
                    if (g > 6 || g < 0) {
                        g = 0;
                    }
                    if (n < 7) {
                        zyQt.push(g);
                    } else {
                        zyKd.push(g);
                    }
                };
                $.each(zyPosition, function(n, e) {
                    getGrade(n, $(e).length && $(e).data().grade);
                });
                zyQt.sort();
                zyKd.sort();
                /* document.getElementById('zhenyuanpin').innerHTML=zyGradeDes[zyQt[0]];*/
                $("#qtGrade").addClass(zyGrade[zyQt[0]]);
                $("#kdGrade").addClass(zyGrade[zyKd[0]]);
            })();
        } else {}
    });

    /**
     * 真元展示汇总信息
     * @author syf
     * @date 2018/11/19
     */
    goodShow.delegate('#qtGrade', 'mouseover', function(e) {
        var boxWrap = document.getElementById('qtGradeitem');
        var val = this;
        var left = this.offsetLeft-155 + this.offsetWidth + 1;
        var top = this.offsetTop + this.offsetHeight + 8;
        boxWrap.style.display = 'block';
        boxWrap.style.left = left + 'px';
        boxWrap.style.top = top + 'px';
    });
    goodShow.delegate('#qtGrade', 'mouseout', function(e) {
        var boxWrap = document.getElementById('qtGradeitem');
        boxWrap.style.display = 'none';
    });

    /**
     * 真元展示汇总信息
     * @author syf
     * @date 2018/11/19
     */
    goodShow.delegate('#kdGrade', 'mouseover', function(e) {
        var boxWrap = document.getElementById('kdGradeitem');
        var val = this;
        var left = this.offsetLeft-155 + this.offsetWidth + 1;
        var top = this.offsetTop + this.offsetHeight + 8;
        boxWrap.style.display = 'block';
        boxWrap.style.left = left + 'px';
        boxWrap.style.top = top + 'px';
    });
    goodShow.delegate('#kdGrade', 'mouseout', function(e) {
        var boxWrap = document.getElementById('kdGradeitem');
        boxWrap.style.display = 'none';
    });





    /*
     * 冰火玄毒(角色)
     * @author maple
     * @date 2013.08.13
     */
    goodShow.delegate('span.role-other-item, .spirit .row', 'mouseover', function(e) {
        var elem = $(e.target);
        var tipId = elem.data('tip');

        /* 如果没有data-tip */
        if (!((tipId || tipId === "0") && $("#" + tipId).length)) {
            return;
        }
        var myPop = new Overlay({
            template: $('#' + tipId),
            align: {
                baseElement: elem,
                selfXY: [-25, -24]
            }
        });
        myPop.show();
        elem.unbind("mouseout").mouseout(function() {
            myPop.hide();
        });
    });

    /**
     * 冰火玄毒(子女)
     * @author maple
     * @date 2013.08.13
     */
    goodShow.delegate('span.skill-item.child-tip', 'mouseover', function(e) {
        var elem = $(this).closest(".skill-item");
        var tipId = elem.data('tip');
        var tmpl = '';

        /* 如果没有data-tip */
        if (!((tipId || tipId === "0") && $("#" + tipId).length)) {
            tmpl = $("#children_x");
        } else {
            tmpl = $('#' + tipId);
        }
        var myPop = new Overlay({
            template: tmpl,
            align: {
                baseElement: elem,
                selfXY: [0, -40]
            }
        });
        myPop.show();
        elem.unbind("mouseout").mouseout(function() {
            myPop.hide();
        });
    });

    /*
     * 万宝镶嵌交互（角色）
     * @author maple
     * @date 2013.07.19
     */
    goodShow.delegate('a.fn-btn-wanbao.enable', 'click', function(e) {
        var wanbaoBtn = goodDetail.find('a.fn-btn-wanbao.enable');
        var wanbaoContent = goodDetail.find('div.fn-wanbao-content');

        if (wanbaoBtn.hasClass("active")) {
            wanbaoBtn.removeClass("active");
            wanbaoContent.hide();
        } else {
            wanbaoBtn.addClass("active");
            wanbaoContent.show();
        }
        return false;
    });

    Style.hover(".practice-item,.animal-item", "hover");

    var deferredJs = function() {
        /*tip颜色转换*/
        var repStr = {
            '#R': '</span><span style="color:red;">',
            '#G': '</span><span style="color:green;">',
            '#B': '</span><span style="color:blue;">',
            '#K': '</span><span style="color:black;">',
            '#P': '</span><span style="color:#f9c;">',
            '#H': '</span><span style="color:#00FFFF;">',
            '#I': '</span><span style="color:#ffc;">',
            '#Y': '</span><span style="color:yellow;">',
            '#W': '</span><span style="color:white;">',
            '#b': '</span><span style="color:#fdeb78;">'
        };
        var tansColorCode = function(dom) {
            var describe = $(dom).find(".attr-describe");
            var html = "";
            describe.length && $.each(describe, function() {
                flag = false;
                html = this.innerHTML;
                html = html.replace(/##/g, "#").replace(/#R|#r|\\n/g, '<br>').replace(/(#[A-Z|a-z])/g, function(args0) {
                    return repStr[args0] || args0;
                }).replace(/#[c|C]([0-9|A-F|a-f]{6})/g, function(args0, args1) {
                    return '</span><span style="color:#' + args1 + ';">';
                }).replace(/#[g|e][0-9|A-F|a-f]{6}/g, '')
                    .replace(/#[b|u]/g, '')
                    .replace(/#([^0-9|A-F|a-f])/g, function(args0, args1) {
                        return args1;
                    });
                this.innerHTML = html;
            });
        };
        /*双完美*/
        var doublePerfectColor = function(dom) {
            if ($(dom).data("goodType") != "equipment") {
                return;
            }
            var aptitudeAttrs = $(dom).find(".aptitude-attr");
            var reg = /\+([0-9]+)%/gi;
            var averageAptitude = 0;
            var regResult;
            switch (aptitudeAttrs.length) {
                case 0:
                    return;
                    break;
                default:
                    $.each(aptitudeAttrs, function() {
                        var text = this.innerHTML;
                        var regObj = new RegExp(reg);
                        regResult = regObj.exec(text);
                        regResult && (averageAptitude += Number(regResult[1]));
                    });
            }
            averageAptitude = averageAptitude / aptitudeAttrs.length;
            if (averageAptitude >= 16) {
                aptitudeAttrs.removeClass("c-p-n").addClass("c-double-perfect");
            }
        };
        /*处理装备物品数据，生成html代码*/
        var tipDataToTemplate = function(tipId) {
            var template, templateTpl = null,
                tipData = {};
            var icon, iconIndex;
            /* 如果没有data-tip */
            if (("" + tipId).indexOf("ch_") == -1 && $("#" + tipId).length < 1) {
                return false;
            }
            if ("0" == tipId || Number(tipId) || ("" + tipId).indexOf("zn_") !== -1 ) {
                /*子女时装*/
                if(("" + tipId).indexOf("zn_") !== -1) {
                    tipData = charObj.infants[0].cardList[6];
                    tipData.typeDesc = "子女时装";
                    tipData.childLevel = 50;
                    tipData.isBind = tipData.bindType == 1 ? 1 : 4;
                    tipData.description = $("#" + tipId).html()+'<p class="c-w-n attr-describe">' + tipData.story + '</p>';
                } else {
                    /*装备，道具*/
                    tipData = charObj && (charObj.items.commonItem[tipId] || charObj.items.equip[tipId] || charObj.items.petEquip[tipId] || charObj.items.card[tipId]);
                    tipData.description = $("#" + tipId).html() || '';
                    /* 区分包裹仓库的子女时装 */
                    if(tipData.dataId >= 60009001 && tipData.dataId <= 60009999) {
                        tipData.typeDesc = "子女时装";
                        tipData.childLevel = 50;
                        if(tipData.story!="")
                        {tipData.description = '<p class="c-w-n attr-describe">' + tipData.story + '</p>';}
                    }
                }

                if (tipData.extType) {
                    tipData._equipment = true;
                }
                if (tipData.extType === 0) {
                    tipData._item = true;
                }
                if (tipData.extType === 2) {
                    tipData._petEquip = true;
                }
                if (!tipData.takeLevel || tipData.takeLevel <= 0) {
                    delete tipData.takeLevel;
                }
                if (!tipData.curFit || !tipData.maxFit || tipData.maxFit <= 0) {
                    delete tipData.curFit;
                }
                if (!tipData.anQiLevel || tipData.anQiLevel <= 0) {
                    delete tipData.anQiLevel;
                }

                if (tipData.specialType === 4) {
                    tipData._wuhunType = true;
                }
                if (tipData.specialType === 1) {
                    tipData._longwenType = true;
                }
                if (tipData.specialType === 2) {
                    tipData._anqiType = true;
                }
                if (tipData.specialType !== 2 || tipData.specialType !== 4) {
                    tipData._xiuliType = true;
                }

                /* 增加神器 */
                if (tipData.specialType === 3) {
                    tipData._shenqiType = true;
                }
                if (tipData.xingJi >= 8) {
                    tipData._xingJi = true;
                }

                /* 增加令牌 */
                if (tipData.specialType === 5) {
                    tipData._lingpaiType = true;
                }
                /*豪侠印*/
                if (tipData.specialType === 6) {
                    tipData._haoxiayinType = true;
                }

                if (!tipData.wuHunLevel || tipData.wuHunLevel <= 0) {
                    delete tipData.wuHunLevel;
                }
                if (tipData.curFixNum < 2 || tipData.curFixNum === 0) {
                    tipData._xiuliRed = true;
                }
                if (tipData.annulOrHarm === 1) {
                    tipData._chuanciHarm = true;
                }
                if (tipData.annulOrHarm === 0) {
                    tipData._chuanciAnnul = true;
                }
                if (tipData.extType && tipData.gemAttr && tipData.slotNum) {
                    tipData._gem = true;
                    var slotNum = tipData.slotNum;
                    tipData._gemAttr = [];
                    for (slotNum; slotNum; slotNum--) {
                        tipData._gemAttr.push({});
                    }
                    $.each(tipData.gemAttr, function(n, e) {
                        var gemIcon, gemIconIndex;
                        gemIcon = e && e.icon;
                        gemIconIndex = gemIcon && gemIcon.lastIndexOf("_");
                        e.iconName = gemIconIndex && gemIcon.substr(0, gemIconIndex);
                        e.iconLoc = gemIconIndex && gemIcon.substr(gemIconIndex + 1);
                        e.IMG_PATH = IMG_PATH;
                        tipData._gemAttr[e.pos] = e;
                    });
                }
                if (tipData.isBind) {
                    var bindList = {
                        "1": "已绑定",
                        "2": "拾取时绑定",
                        "3": "装备时绑定",
                        "4": "未绑定"
                    };
                    tipData._bindState = bindList[tipData.isBind];
                }

                tipData.isMaxDwLevel = tipData.maxDWUse == -1 ? true : false;
                tipData.isMaxDwLevelEx = tipData.maxDWUseEx == -1 ? true : false;
                if (tipData.haveDiaoWen) {
                    if (tipData.maxDWUse === -1) {
                        tipData._diaowen = "此雕纹已达到满级";
                    } else {
                        tipData._diaowen = tipData.curDWUse + "/" + tipData.maxDWUse;
                    }
                }
                if (tipData.compandLevel) {
                    if (tipData.compandLevel === 100) {
                        tipData._longwen = "成长等级已达到满级";
                    } else {
                        tipData._longwen = tipData.curFeedNum + "/" + tipData.maxFeedNum;
                    }
                }
                if (tipData._longwenType && tipData.compandLevel) {
                    if (tipData.compandLevel === 100) {
                        tipData._longwenLevel = "成长等级已达到满级";
                    } else {
                        tipData._longwenLevel = tipData.curFeedNum + "/" + tipData.maxFeedNum;
                    }
                }
                if (tipData._wuhunType && tipData.compandLevel) {
                    if (tipData.compandLevel >= 100) {
                        tipData._wuhunLevel = "满级";
                    } else {
                        tipData._wuhunLevel = tipData.compandLevel;
                    }
                }
                if (tipData.aptitudeIsIdentify === 0 && tipData.typeDesc !== "时装") {
                    tipData._aptitudeNotIdentify = true;
                }
                if (tipData.isIdentify === 0) {
                    tipData._petNotIdentify = true;
                }
                if (!tipData.wuxing || tipData.wuxing === "未知") {
                    delete tipData.wuxing;
                }
                templateTpl = tlEquipTpl;
            } else if (tipId.indexOf("gt_") !== -1) {
                /*二套宝石*/
                var i = tipId.split("_");
                var gemData = charObj && charObj.SecondGemInfo[i[1]].gems;
                $.each(gemData, function(n, gem) {
                    if (gem.pos == i[2]) {
                        tipData = gem;
                        tipData.icon = tipData.gemIcon;
                    }
                });
                tipData.description = $("#" + tipId).html();
                templateTpl = tlGemTpl;
            } else if (tipId.indexOf("zy_") !== -1) {
                /*真元*/
                tipData = charObj && (charObj.zhenYuanList[tipId.substr(3)]);
                tipData.description = $("#" + tipId).html();
                templateTpl = tlZhenyuanTpl;
            } else if (tipId.indexOf("ch_") !== -1) {
                /*子女*/
                tipData = charObj && (charObj.items.card[tipId.substr(3)]);
                templateTpl = tlChildrenTpl;
            }
            icon = tipData && tipData.icon;
            iconIndex = icon && icon.lastIndexOf("_");
            tipData.iconName = iconIndex && icon.substr(0, iconIndex);
            tipData.iconLoc = iconIndex && icon.substr(iconIndex + 1);
            tipData.IMG_PATH = IMG_PATH;
            template = (templateTpl && templateTpl(tipData)) || $("#" + tipId).html();
            return template;
        };
        /**
         * tip事件
         */
        goodShow.delegate(".has-tip i", "mouseover", function() {
            if (!charObj) {
                return false;
            }
            var val = this;
            var t = $(val).closest(".has-tip");
            var tipId = t.data("tip");
            var x = t.width();
            var h = t.height();
            var tipTemplate = tipDataToTemplate(tipId);
            var shimTemplate = "";
            (x > 34) ? (shimTemplate = $('<span class="role-good-item-shim64"></span>')) : (shimTemplate = $('<span class="role-good-item-shim32"></span>'));
            shimTemplate.html('<a href="javascript:;" title="向上" class="up"></a><a href="javascript:;" title="向下" class="down"></a>');
            if (!tipTemplate) {
                return;
            }
            var myPop = new Overlay({
                template: tipTemplate,
                align: {
                    baseElement: t,
                    selfXY: [-x - 10, 0]
                }
            });
            myPop.before("show", function() {
                tansColorCode(this.element);
                doublePerfectColor(this.element);
            });
            myPop.after("show", function() {
                var tip = $(this.element),
                    speed = 100,
                    overHeight = false;
                var elemHeight = this.element.height();
                var cleintHeight = $(window).height();
                var scrollTop = $(document).scrollTop();
                if (elemHeight + 45 > cleintHeight) {
                    this.element.css("top", scrollTop + 45);
                    overHeight = true;
                } else if (t.offset().top - scrollTop + elemHeight + h > cleintHeight) {
                    this.element.css("top", scrollTop + 45 + (cleintHeight - 50 - elemHeight));
                }
                if (overHeight) {
                    var myPopShim = new Overlay({
                        template: shimTemplate,
                        align: {
                            baseElement: t,
                            selfXY: ["-" + t.css("paddingLeft"), "-" + t.css("paddingTop")]
                        }
                    });
                    myPopShim.after("hide", function() {
                        this.element.remove();
                        this.destroy();
                    });
                    myPopShim.after("show", function() {
                        var trigger = this.template;
                        $(trigger).find(".down").unbind("hover").hover(function() {
                            var elemHeight = tip.height();
                            var cleintHeight = $(window).height();
                            var scrollTop = $(document).scrollTop();
                            var offsetTop = tip.offset().top;
                            var animateHeight = offsetTop + elemHeight - scrollTop - cleintHeight + 10;
                            tip.stop();
                            tip.animate({
                                top: offsetTop - animateHeight
                            }, animateHeight / speed * 1000);
                        });
                        $(trigger).find(".up").unbind("hover").hover(function() {
                            var scrollTop = $(document).scrollTop();
                            var offsetTop = tip.offset().top;
                            var animateHeight = scrollTop - offsetTop + 45;
                            tip.stop();
                            tip.animate({
                                top: offsetTop + animateHeight
                            }, animateHeight / speed * 1000);
                        });
                        $(trigger).unbind("mouseleave").mouseleave(function() {
                            myPopShim.hide();
                            myPop.hide();
                        });
                    });
                    var s = setTimeout(function() {
                        myPopShim.show();
                        t.unbind("mouseout");
                    }, 100);
                    t.unbind("mouseout").mouseout(function() {
                        myPopShim.hide();
                        myPop.hide();
                        clearTimeout(s);
                    });
                    $(this.element).unbind("mouseenter").mouseenter(function() {
                        myPopShim.hide();
                        myPop.hide();
                    });
                } else {
                    t.unbind("mouseout").mouseout(function() {
                        myPop.hide();
                    });
                }
                myPop.after("hide", function() {
                    tip.stop();
                    this.element.remove();
                    this.destroy();
                });
            });
            myPop.show();
        });
    };
    deferredJs();

    /**
     * 御兽Tips
     * @author maple
     * @date 2014.03.05
     */
    goodShow.delegate('.yushou_box i', 'mouseover', function(e) {
        var boxWrap = document.getElementById('boxWrap');
        var val = this;
        var thisText = val.innerHTML;
        var tempArr = thisText.split(';');
        var activeStr = '',valueStr = '',qlValut = '',cfStr = '';
        for(i=0;i<tempArr.length;i++){
            var temp = tempArr[i].split(':');

            //var temp = thisText.split(':');
            if(temp[0] == 0){
                activeStr = "<h4 class='is_no'>该穴位尚未激活</h4>";
                var endTemp = temp.length-2;
                qlValut = '<p>激活需要契灵值：'+ temp[endTemp] + '</p>';
            }else{
                activeStr = "<h4 class='is_ok'>该穴位已激活</h4>";
            }
            if(temp[4] == 0){
                cfStr = "出战珍兽";
            }else{
                cfStr = "附体珍兽";
            }
            switch (parseInt(temp[1]))
            {
                case 0: valueStr += '<p>' + cfStr + '血上限：+'+ temp[2]+ '%</p>';
                    break;
                case 1: valueStr += '<p>' + cfStr + '外功攻击：+'+ temp[2] + '%</p>';
                    break;
                case 2: valueStr += '<p>' + cfStr + '内功攻击：+'+ temp[2] + '%</p>';
                    break;
                case 3: valueStr += '<p>' + cfStr + '外功防御：+'+ temp[2] + '%</p>';
                    break;
                case 4: valueStr += '<p>' + cfStr + '内功防御：+'+ temp[2] + '%</p>';
                    break;
                case 5: valueStr += '<p>' + cfStr + '闪避：+'+ temp[2] + '%</p>';
                    break;
                case 6: valueStr += '<p>' + cfStr + '命中：+'+ temp[2] + '%</p>';
                    break;
                case 7: valueStr += '<p>' + cfStr + '会心攻击：+'+ temp[2] + '%</p>';
                    break;
                case 8: valueStr += '<p>' + cfStr + '会心防御：+'+ temp[2] + '%</p>';
                    break;
                case 9: valueStr += '<p>' + cfStr + '力量资质：+'+ temp[2] + '%</p>';
                    break;
                case 10: valueStr += '<p>' + cfStr + '灵气资质：+'+ temp[2] + '%</p>';
                    break;
                case 11: valueStr += '<p>' + cfStr + '体力资质：+'+ temp[2] + '%</p>';
                    break;
                case 12: valueStr += '<p>' + cfStr + '定力资质：+'+ temp[2] + '%</p>';
                    break;
                case 13: valueStr += '<p>' + cfStr + '身法资质：+'+ temp[2] + '%</p>';
                    break;
                default: valueStr += '';
                    break;
            }
        }
        var tmpl = '<div id="fBox" class="fBox" style="display:block;">'
            + '<div class="fBox_top"></div>'
            + activeStr + valueStr + qlValut
            + '<div class="fBox_btm"></div>'
            + '</div>';
        var left = this.offsetLeft + this.offsetWidth + 1;
        var top = this.offsetTop + this.offsetHeight + 1;
        boxWrap.style.display = 'block';
        boxWrap.innerHTML = tmpl;
        val.parentNode.appendChild(boxWrap);
        var objFBox = document.getElementById('fBox');
        objFBox.style.left = left + 'px';
        objFBox.style.top = top + 'px';
    });
    goodShow.delegate('.yushou_box i', 'mouseout', function(e) {
        var boxWrap = document.getElementById('boxWrap');
        boxWrap.style.display = 'none';
    });





    /**
     * 心诀
     * @author maple
     * @date 2013.08.13
     */
    goodShow.delegate('.xinjuehas-tip i', 'mouseover', function(e) {
        var elem = $(this).closest(".xinjuehas-tip");
        var tipId = elem.data('tip');
        var tmpl = '';


        /* 如果没有data-tip */
        if (!((tipId || tipId === "0") && $("#" + tipId).length)) {
            tmpl = $("#children_x");
        } else {
            tmpl = $('#' + tipId);
        }
        var myPop = new Overlay({
            template: tmpl,
            align: {
                baseElement: elem,
                selfXY: [-65, 40]
            }
        });
        myPop.show();
        elem.unbind("mouseout").mouseout(function() {
            myPop.hide();
        });
    });






    /**
     * 子女Tips
     * @author maple
     * @date 2014.03.05
     */
    goodShow.delegate('.child-has-tip i', 'mouseover', function(e) {
        if (!charObj.infants || charObj.infants.length < 1) {
            return "children not exists";
        }

        /* 现在为单子女 */
        if (!charObj.infants[0].cardList || charObj.infants[0].cardList.length < 0) {
            return "the cardList of children not exists";
        }

        var val = $(e.target);
        var t = $(val).closest(".child-has-tip");
        var index = t.data("id");
        var h = t.height();
        var childrenTip = new Overlay({
            template: tlChildrenTpl(charObj.infants[0].cardList[index]),
            align: {
                baseElement: t,
                selfXY: [-44, 0]
            }
        });
        childrenTip.after("hide", function() {
            this.element.remove();
            this.destroy();
        });
        childrenTip.after("show", function() {
            var tip = $(this.element),
                overHeight = false;
            var elemHeight = this.element.height();
            var cleintHeight = $(window).height();
            var scrollTop = $(document).scrollTop();
            if (elemHeight + 45 > cleintHeight) {
                this.element.css("top", scrollTop + 45);
            } else if (t.offset().top - scrollTop + elemHeight > cleintHeight) {
                this.element.css("top", scrollTop + 45 + (cleintHeight - 50 - elemHeight));
            }
        });
        t.unbind("mouseout").mouseout(function() {
            childrenTip.hide();
        });
        childrenTip.show();
    });

    /**
     * 套装属性Tips
     * @author maple
     * @date 2015.07.22
     */
    goodShow.delegate('#J_RoleImg', 'mouseover', function(e) {
        var t = $(e.target);
        var h = t.height();

        if(charObj.equipEnchanceSetAttackLevel==undefined || charObj.equipEnchanceSetAttackLevel==undefined) {
            return;
        }

        switch(charObj.equipEnchanceSetAttackLevel) {
            case 0:
                charObj._TRLevel0 = true;
                break;
            case 1:
                charObj._TRLevel1 = true;
                break;
            case 2:
                charObj._TRLevel2 = true;
                break;
            case 3:
                charObj._TRLevel3 = true;
                break;
            case 4:
                charObj._TRLevel4 = true;
                break;
        }

        switch(charObj.equipEnchanceSetDefenceLevel) {
            case 0:
                charObj._DPLevel0 = true;
                break;
            case 1:
                charObj._DPLevel1 = true;
                break;
            case 2:
                charObj._DPLevel2 = true;
                break;
            case 3:
                charObj._DPLevel3 = true;
                break;
            case 4:
                charObj._DPLevel4 = true;
                break;
        }

        var tlTRLevelTip = new Overlay({
            template: tlTRLevelTpl(charObj),
            width: 306,
            align: {
                baseElement: t,
                selfXY: [-25, -24]
            }
        });
        tlTRLevelTip.after("hide", function() {
            this.element.remove();
            this.destroy();
        });
        tlTRLevelTip.after("show", function() {
            var tip = $(this.element);
            var elemHeight = this.element.height();
            var cleintHeight = $(window).height();
            var scrollTop = $(document).scrollTop();
            if (elemHeight + 45 > cleintHeight) {
                this.element.css("top", scrollTop + 45);
            } else if (t.offset().top - scrollTop + elemHeight > cleintHeight) {
                this.element.css("top", scrollTop + 45 + (cleintHeight - 50 - elemHeight));
            }
        });
        t.unbind("mouseout").mouseout(function() {
            tlTRLevelTip.hide();
        });
        tlTRLevelTip.show();
    });
    /**
     * 侠印Tips
     * @author maple
     * @date 2014.03.05
     */
    goodShow.delegate('.xy-ico', 'mouseover', function(e) {
        var boxWrap = $(e.target);
        $(boxWrap).parent().find(".fBox").show();
    });
    goodShow.delegate('.xy-ico', 'mouseout', function(e) {
        var boxWrap = $(e.target);
        $(boxWrap).parent().find(".fBox").hide();
    });
});



